How to Change the SSH Port for Your Linux Server
Port 22 is used to establish an SSH connection by default. You can strengthen the server security by modifying the SSH port to prevent brute force attacks. This article will show you how to change the SSH port for your Linux Server.
1. Log in to your Linux Server
To log in to the Linux server, please refer to How to connect to a Linux Server using XShell or PuTTy.
If the system is Ubuntu OS, please switch to root user with the command sudo -i
.
2. Edit the SSH configuration file
The SSH configuration file is sshd_config. You can use "vi" to edit the configuration. First, enter the command below.
vi /etc/ssh/sshd_config
Next, type "/Port" to search for the
Please note that the port number must be between 1024 and 65536.
3. Save the configuration file and exit
Save the configuration file and exit with the command :wq
.
4. Restart the SSH service
Restart the SSH service for the configuration to take effect.
service sshd restart
5. Log in to the server with the new port
After you change the SSH port, the session breaks. You need to log back in to the server using the new port.